<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>접수</title>
<link rel="stylesheet"
	href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="resources/css/patient/reservation.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<script>
		var name="";
		var doctor_id;
		var dept_id;
		var dept_name;
		var is_night;
		var is_holiday;
		var jupsoo_code_id;
		var idx="";
		var thisday="";	
		var bohum_code;
		var res_time;
		var idx;
		
		function fn_selectcal(){
			doctor_id = $("#sel_doc").val();
			$.ajax({
				url: 'showschedule.do',
				data: 'doctor_id='+doctor_id,
				async:false,
				success: function(data2) {
					for(var i =0; i<data2.schedulelist.length;i++){
						$enableDay = data2.schedulelist[i].sdate;
						var $s = data2.schedulelist[i].res_time;
					}
			  	}
			});
		}

		$(document).ready(function(){
			$("#select_D").focus();
			$(document).on("click",".nameTr2",function(){
				$("#check2").empty();
				idx = $(".nameTr2").index(this);
				bohum_code=$("#bohum").val();
				var id = $("input[name='schedule_id']").eq(idx).val();
				res_time = $("input[name='res_time']").eq(idx).val();
				var reser = "";
				reser+="<table id='sidetable1'>";
				reser+="<tr><th>의사명</th><th>예약날짜</th><th>예약시간</th></tr>";
				reser+="<tr><td>"+name+"</td><td>"+thisday+"</td><td>"+res_time+"</td></tr>";
				reser+="<tr><td colspan='3'><button id='reser' onclick='add();'>예약하기</button></td></tr>";
				reser+="</table>";
				$("#check2").html(reser);
			});	
			
			selectjupsoo = function(){
				var type = $('#jupsoo_code_id option:selected').val();
				//alert("접수 유형 : " + type);
				if(type == 'jcode01'){
					fn_jupsoo();
				}else if(type == 'jcode02'){
					fn_ward();
				}
			}
		});
		
		function fn_selectcal(){
			doctor_id = $("#sel_doc").val();
			$.ajax({
				url: 'showschedule.do',
				data: 'doctor_id='+doctor_id,
				async:false,
				success: function(data2) {
					enableDay = data2.enableDay;
					for(var i =0; i<schedulelist.length;i++){
						var $s =data2.schedulelist[i].res_time;
					}
			  	}
			});
		}

		function add(){
			var reser2="";

			reser2+="<form id='addsubmit' action='addjupsoo.do'>";
			reser2+="<input type='hidden' name='bohum_code_id' value='"+bohum_code+"'>";
			reser2+="<input type='hidden' name='patient_id' value='${patient_id}'>";
			reser2+="<input type='hidden' name='doctor_id' value='"+doctor_id+"'>";				
			reser2+="<input type='hidden' name='jupsoo_date' value='${currentdate}''>";
			reser2+="<input type='hidden' name='is_night' value='"+is_night+"'>";
			reser2+="<input type='hidden' name='is_holiday' value='"+is_holiday+"'>";
			reser2+="<input type='hidden' name='jupsoo_code_id' value='"+jupsoo_code_id+"'>";
			$(".reservation3Div").append(reser2);
			$("#addsubmit").submit();
		}
		
		function fn_selectChange(){
			dept_id = $(this).val();
			dept_name = $("#select_D option:selected").text();
			$.ajax({
				url: 'selectdoctor.do',
				data: 'dept_id='+dept_id,
				dataType : "json",
				success: function(data) {
					var opt = "<option selected>- 담당의사 선택 -</option>";
					$("#sel_doc").html(opt);
					for (i = 0; i < data.doctorlist.length; i++) {
						var opt2 = "<option value='"+data.doctorlist[i].doctor_id+"'>"+data.doctorlist[i].name+"</option>";

						$("#sel_doc").append(opt2);
					}
			  	}
			});
			$("#sel_doc").bind("change", fn_selectcal);
		}

		$("#tabs").tabs();

		$(document).ready(function(){
			$("#select_D").bind("change", fn_selectChange);	
		});
				
		function fn_jupsoo(){
			var reser = "";
			is_night=$("#is_night").val();
			is_holiday = $("#is_holiday").val();
			jupsoo_code_id = $("#jupsoo_code_id").val();
			is_night=$("#is_night").val();
			is_holiday = $("#is_holiday").val();
			jupsoo_code_id = $("#jupsoo_code_id").val();
			bohum_code=$("#bohum").val();
			
			reser+="<table id='sidetable1'>";
			reser+="<tr><th>의사번호</th><th>환자번호</th><th>예약날짜</th><th>보험여부</th><th>공휴일</th>";
			reser+="<th>야간</th><th>접수유형</th></tr>"; 
			reser+="<tr><td>"+doctor_id+"</td><td>${patient_id}</td><td>${currentdate}</td><td>"+bohum_code+"</td><td>"+is_holiday+"</td>";
			reser+="<td>"+is_night+"</td><td>"+jupsoo_code_id+"</td></tr></table>";
			reser+="<table><tr><td><input type='button' id='reser' onclick='add();' value = '진료접수하기'></td>";
			reser+="<td><input type='button' id='jindan' onclick='jindan();' value= '진단서접수하기'></td></tr>";
			reser+="</table>";
			$(".reservation3Div").html(reser);
		}
			
		function jindan(){
			var reser2="";
			reser2+="<form id='addsubmit2' action='addjindan.do'>";
			reser2+="<input type='hidden' name='bohum_code_id' value='"+bohum_code+"'>";
			reser2+="<input type='hidden' name='patient_id' value='${patient_id}'>";
			reser2+="<input type='hidden' name='doctor_id' value='"+doctor_id+"'>";
			reser2+="<input type='hidden' name='jupsoo_date' value='${currentdate}''>";
			reser2+="<input type='hidden' name='is_night' value='"+is_night+"'>";
			reser2+="<input type='hidden' name='is_holiday' value='"+is_holiday+"'>";
			reser2+="<input type='hidden' name='jupsoo_code_id' value='"+jupsoo_code_id+"'></form>";
			$(".reservation3Div").append(reser2);
			$("#addsubmit2").submit();
		}
			
		function fn_ward(){
			//alert($("#bohum").val());
			is_night="<form id='wardjupsoo' action='roomselect.do'><input type='hidden' name='is_night' value='"+$("#is_night").val()+"'>";
			is_holiday = "<input type='hidden' name='is_holiday' value='"+$("#is_holiday").val()+"'>";
			jupsoo_code_id = "<input type='hidden' name='jupsoo_code_id' value='"+$("#jupsoo_code_id").val()+"'>";
			bohum_code_id="<input type='hidden' name='bohum_code_id' value='"+$("#bohum").val()+"'>";
			doctor_id ="<input type='hidden' name='doctor_id' value='"+$("#sel_doc").val()+"'>"; 
			jupsoo_date="<input type='hidden' name='jupsoo_date' value='${currentdate}''>";
			patient_id="<input type='hidden' name='patient_id' value='${patient_id}'></form>";

			$(".reservation3Div").append(is_night+is_holiday+jupsoo_code_id+bohum_code_id+jupsoo_date+doctor_id+patient_id);
			$("#wardjupsoo").submit();	
		}
</script>
</head>
<body>
	<div id="systembase">
		<!-- 환자 정보 시작 -->
		<div id="systempatient">
			<h3 id="systemmenufont">환자정보</h3>
				<table class="patiend_info_table">
					<tr>
						<td>고유번호</td>
						<td>이름</td>
						<td>성별</td>
						<td>주민번호</td>
						<td>국민보험</td>
						<td>자동차보험</td>
						<td>산업재해보험</td>
						<td>우편번호</td>
						<td>우편번호2</td>
						<td>기본주소</td>
						<td>상세주소</td>
						<td>연락처</td>
					</tr>
					<tr>
						<td>${patient.patient_id}</td>
						<td>${patient.name }</td>
						<td>${patient.gender }</td>
						<td>${patient.jumin1 }-${patient.jumin2 }</td>
						<td>${patient.is_kuk }</td>
						<td>${patient.is_car }</td>
						<td>${patient.is_san }</td>
						<td>${patient.zipcode1 }</td>
						<td>${patient.zipcode2 }</td>
						<td>${patient.addr1 }</td>
						<td>${patient.addr2 }</td>
						<td>${patient.tel }</td>
					</tr>
				</table>
		</div>
		<!-- 환자 정보 끝 -->
	<div class="jup_content">
	<h3 id="systemmenufont">환자 예약접수</h3>
			<!-- 진료과 선택 -->
				<table class="jup_table">
				<tr>
				<td>
				<select id="select_D">
						<option selected>-진료과 선택 -</option>
						<c:set var="deptlist2" value="${deptlist }" />
						<c:forEach var="dept" items="${deptlist2}">
							<option  id="select_D2" value="${dept.dept_id }">${dept.name}</option>
						</c:forEach>
					</select>
				</td>
				<td>		
				<!-- 담당의사 -->
					<select id="sel_doc">
						<option selected>- 담당의사 선택 -</option>
					</select>
				</td>			
				<td>			
				<!-- 보험가입 유무 -->
				<select id="bohum" name="bohum">
						<option selected>- 보험 유형 선택 -</option>
						<option value="BO2">국민보험</option>
						<option value="BO3">자동차보험</option>
						<option value="BO4">상해보험</option>
					</select>
				</td>
				<td>
				<select id="is_night" name="is_night">
						<option selected>- 야간여부 -</option>
						<option value="N">일반</option>
						<option value="Y">야간</option>
					</select>
				</td>
				<td>
					<select id="is_holiday" name="is_holiday">
						<option selected>- 공휴일여부 -</option>
						<option value="N">일반</option>
						<option value="Y">공휴일</option>
					</select>
				</td>
				<td>
					<select id="jupsoo_code_id" name="jupsoo_code_id">
						<option selected>- 접수여부 -</option>
						<option value="jcode01">외래</option>
						<option value="jcode02">입원</option>
					</select>
				</td>
				</tr>
				</table>
			<!-- 달력 -->
			<div class="reservation3Div">
			</div>
		</div>
	</div>

	<!-- 오른쪽 환자 대기 리스트 시작 -->
	<div id="systembaseside">
		<h2 style="margin-left: 30px; height:20px;"></h2>
		<hr>
		<div class="list_table">
			<font size="3px" color="white">접수 날짜</font><br>
			<input type="text" id="currentDate"  value="${currentdate }" readonly >
				<table id="sidetable" style="border: 0px white solid;">
					<tr>
						<td style="border: 0px white solid;">
							<input id ="jupsoo" type="button" value="접수" onclick="selectjupsoo();">
						</td>
					</tr>
			</table>
		</div>
		<div class="list_table2">
		</div>
	</div>
	<!-- 오른쪽 환자 대기 리스트 끝 -->
</body>
</html>